#ifndef PARSER_H
#define PARSER_H

#include <iostream>
#include <vector>
#include <sstream>
#include <cstdlib>
#include <strings.h>
#include <cstring>
#include <fstream>
#include <math.h>
#include <algorithm>

using namespace std;

/**
 * \brief Parser creator
 *
 * This class provides a Robocup parser
 */

class Parser
{

public:
  void change (float [6], float [6]);

    int stamina;    /** Energy level . */ //(stamina Stamina Effort)
    int effort;     /** Effort. */
    int clock;	 /** Clock. */
    float speed [2] /** Speed and angle of running. */;//(speed Speed Angle)
    int head_angle; /** The angle btw the neck and the body of the player. */ //(head_angle Angle)

    vector <int> counters;      /** This vector keeps the number of invoked actions.*///(kick dash turn say turn_neck catch move change_view)
    vector <int> distPlayers;   /** This vector keeps the relative distance of all the players that we see at the moment.*/
    vector <int> dirPlayers;    /** This vector keeps the relative direction of all the players that we see at the moment.*/

    float mygoal[6]; /**My goal. */
    float theirgoal[6]; /** Their goal. */

    float p_id[1];      /** Player's identity number */
    float player[6];    /** Player's relative position and identity (distance, direction, team, id) */
    string team_name;   /** Player's team name **/

    float ball[6];          /** Ball relative position from the player. */
    float line_r[6];        /** Relative position of the right line football field from the player. */ //línea derecha
    float line_l[6];        /** Relative position of the left line football field from the player. */ //línea izquierda

    float line_b[6];        /** Line b relative position from the player. */
    float line_t[6];        /** Line t relative position from the player. */

    float flag_c[6];        /** Flag c relative position from the player. */ //centro
    float flag_c_t [6];     /** Flag c t relative position from the player. *///centro arriba
    float flag_c_b [6];     /** Flag c b relative position from the player. */ //centro abajo

    float flag_l_t [6];       /** Flag l t relative position from the player. */
    float flag_r_t [6];       /** Flag r t relative position from the player. */
    float flag_l_b [6];       /** Flag l b relative position from the player. */
    float flag_r_b [6];       /** Flag r b relative position from the player. */

    float flag_g_l_t [6];   /** Flag g l t relative position from the player. *///portería izq arriba
    float goal_l[6];        /** Left goal relative position from the player. *///portería izquierda
    float flag_g_l_b [6];   /** Flag g l b relative position from the player. *///portería izq abajo

    float flag_g_r_t [6];   /** Flag g r t relative position from the player. *///portería dcha arriba
    float goal_r[6];        /** Right goal relative position from the player. *///portería derecha
    float flag_g_r_b [6];   /** Flag g r b relative position from the player. *///portería dcha abajo

    float flag_p_l_c [6];   /** Flag p l c relative position from the player. *///portería izq
    float flag_p_r_c [6];   /** Flag p l c relative position from the player. *///portería izq


    unsigned int time; /** Time. */


    string field; /** Field where the players are. */


    //Miscellaneous

    bool objectball;    /** Boolean variable to check if we have seen the ball in this cycle. */
    bool goal;          /** Boolean variable which becomes true when a goal is scored. */
    bool foul;          /** Boolean variable which becomes true when a foul is produced. */
    bool drop_ball;     /** Boolean variable which becomes true when the ball is dropped. */
    bool play_on;       /** Boolean variable which becomes true when the play mode changes to play_on. */
    bool kick_off;       /** Boolean variable which becomes true when there is a kick_off. */
    bool free_kick;	/** Boolean variable which becomes true when there is a free_kick. */
    bool free_kick_foul;	/** Boolean variable which becomes true when there is a free_kick_foul. */
    bool corner_kick;	/** Boolean variable which becomes true when there is a corner_kick.*/
    bool offside;	/** Boolean variable which becomes true when there is a offside. */
    bool half_time;	/** Boolean variable which becomes true when there is a half_time. */
    bool kick_in;
    bool goal_kick;
    bool goalie_catch_ball;
    bool before_kick_off;

    bool nearertoball;

bool searching;

    //functions

    /**
     * \brief Parser default constructor
     *
     */
    Parser();

    /**
     * \brief This main function executes all our parser functions.
     */
    void parse (string &data);

    /**
     * \brief Finds the relative position of the other players respect one
     */
    void findplayer(string &str, float id[], string &team, float see_info[]);

    /**
     * \brief Finds the relative position (in float numbers) of one object respect the player
     */
    void findfloats(string &str, const string name, float see_info[]);

    /**
     * \brief Finds the value (in integer numbers) of a player atribute.
     *
     * \returns The value of this atribute.
     */
    int  findint(string &str, const string name);

    /**
     * \brief Finds two values (in integer numbers) of a player atributes.
     */
    void findint2(string &str, const string name, int values[]);

    void findint2(string &str, const string name,  int &value1,  int &value2); //sobrecarga

    /**
     * \brief Finds a string of a player atributes.
     *
     * \returns Theis string.
     */
    string  findstring(string &str, const string name);

    /**
     * \brief With this funtcion we collect the referee(arbiter/arbitrator) messages.
     */
    void hear(string &str, const string name);

    /**
     * \brief With this funtcion we place all the players in their initial position.
     */
    void getInitPos(vector<int> &,unsigned short, string);

    /**
     * \brief With this funtcion we initialize all the variables at the beginnin of each iteration.
     */
    void init();
};

#endif // PARSER_H
